<script lang="ts">
import type { SetupContext, VNode } from 'vue'
import type { RouteLocationNormalizedLoaded } from 'vue-router'
import { h, KeepAlive, toRaw } from 'vue'
import { reDefineComponent, includes } from './hooks/useComponent'

export default {
    name: 'CacheAlive',
    props: {
        is: {
            type: Object,
            require: true
        },
        route: {
            type: Object,
            require: true
        },
        currentRouteViewKey: {
            type: String,
            require: true
        }
    },
    setup(props) {
        return () =>
            h(
                KeepAlive,
                { include: toRaw(includes.value) },
                {
                    default: () =>
                        reDefineComponent({
                            Component: props.is as VNode,
                            route: props.route as RouteLocationNormalizedLoaded,
                            key: props.currentRouteViewKey
                        })
                }
            )
    }
}
</script>
